/**
 * Created by Administrator on 2019/5/20.
 */
var year = Number(prompt("请输入年份"));
var month = Number(prompt("请输入月份"));
function runnian(year) {
    if(year%400==0||year%4==0&&year%100!=0){
        return true
    }
    else {
        return false
    }
}
var days =0;
for(i=1980;i<year;i++){
    if (runnian(i)){
        days+=366;
    }  else {
        days+=365
    }
}
/**/

for(var k=1;k<month;k++){
    switch(k) {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10 :
        case 12 :
            days+=31;
            break;
        case 2:
            if(runnian(year)){
                days+=29
            }else {
                days+=28
            }
            break;
        case 4:
        case 6:
        case 9:
        case 11:
          days+=30;
            break;
    }
}
days+=2;
var start = days %7;
var day = document.querySelector("#day");
var thisdays = 0;
    switch(month) {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10 :
        case 12 :
            thisdays+=31;
            break;
        case 2:
            if(runnian(year)){
                thisdays+=29
            }else {
                thisdays+=28
            }
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            thisdays+=30;
            break;
    }

var pday =0;
switch(month-1) {
    case 0:
    case 1 :
    case 3 :
    case 5 :
    case 7 :
    case 8 :
    case 10 :
    case 12 :
        pday+=31;
        break;
    case 2:
        if(runnian(year)){
            pday+=29
        }else {
            pday+=28
        }
        break;
    case 4:
    case 6:
    case 9:
    case 11:
        pday+=30;
        break;
}
for( var l =pday-start+1; l<=pday; l++ ){
    day.innerHTML += '<span class="h">'+ l+'</span>'
}
var s = new Date().getDate();
for(var d =1 ;d<=thisdays;d++){
    if(d===s){
        day.innerHTML+= '<span class="today">'+d+'</span>'
    }
    else{
        day.innerHTML+= '<span >'+d+'</span>'
    }
}
var all =42;
var endday =all-start-thisdays;
for(var p =1;p<=endday;p++){
    day.innerHTML+= '<span class="h">'+p+'</span>'
}
document.querySelector('#nian').innerHTML+=year;
document.querySelector('#yue').innerHTML+=month;
